//"Welcome to Beijing to"

// [Welcome, to, Beijing, to]

// Welcome: 1
// {}

package main

import (
	//"golang.org/x/tour/wc"
	"strings"
	"fmt"
)


//如何安装github和golang依赖包

//打开终端：执行如下命令即可

//$ go get golang.org/x/tour/wc
//$ go get github.com/cheekybits/genny/generic



// Welcome to Beijing to
func WordCount(s string) map[string]int {
	fmt.Println(s)
	strArray := strings.Fields(s)
	//[Welcome , to, Beijing, to]
	fmt.Println(strArray)
	// key：单词，value：单词个数
	count := make(map[string]int)

	for i := 0;i < len(strArray); i++{
		// 把数组里面的单词取出来
		str := strArray[i]
		// 根据key取值
		_,ok := count[str]
		if !ok{ //不存在
			count[str] = 1
		} else { //key已经存在
			count[str] += 1
		}
	}
	return count
}

func main() {
	//wc.Test(WordCount)
	fmt.Println(WordCount("li yue chun li"))
}